package com.wechat.servlet.Utils;

import com.alibaba.fastjson.JSONArray;
import com.wechat.DAO.DaoImpl.UserInfoDAOIpml;
import com.wechat.DAO.UserInfoDAO;
import com.wechat.pojo.UserInfo;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class SearchUserInfo {
    public static boolean search(String username, HttpServletResponse response){
        UserInfoDAO userInfoDAO = new UserInfoDAOIpml();
        UserInfo resInfo = userInfoDAO.query(username);
        if(resInfo == null){
            return false;
        }
        System.out.println(resInfo);
//                转Json
        Object obj = JSONArray.toJSON(resInfo);
//        JSONArray jsonArray = new JSONArray();
        // ??
//        jsonArray.add(obj);
//        jsonArray.add(obj);
//        System.out.println(jsonArray.toString());
        //
        String json = obj.toString();
        System.out.println(json);
        String base64Json = Base64Encoder.encode(json);
        try {
            response.getWriter().write(base64Json);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return true;
    }
}
